package sc.common.stringprocessor;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class ShortNameGenerator {

	List<List<StringProcessor>> processorGroups;

	public String gen(String fullName, int minLength) {
		String curName = fullName;
		for (List<StringProcessor> processorGroup : processorGroups) {
			for (StringProcessor processor : processorGroup) {
				String tempName = processor.process(curName);
				if (!StringUtils.equals(tempName, curName)) {
					if (StringUtils.length(tempName) >= minLength) {
						curName = tempName;
					}
					break;
				}
			}
		}
		return curName;
	}

	public void addGroup(List<StringProcessor> processorGroup) {
		getProcessorGroups().add(processorGroup);
	}

	public List<List<StringProcessor>> getProcessorGroups() {
		if (processorGroups == null) {
			processorGroups = new ArrayList<List<StringProcessor>>();
		}
		return processorGroups;
	}

}
